package com.tenton.service.Impl;

import com.tenton.mapper.OrdersMapper;
import com.tenton.pojo.Orders;
import com.tenton.service.OrdersService;
import com.tenton.utils.MybatisUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * @Date: 2021/1/21
 * @Author: Tenton
 * @Description:
 */
public class OrdersServiceImpl implements OrdersService {
    /**
     * 新增订单
     * @param ordersList
     * @return
     */
    @Override
    public int insertOrder(List<Orders> ordersList) {
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        OrdersMapper mapper = sqlSession.getMapper(OrdersMapper.class);
        int result = mapper.insertOrder(ordersList);
        return result;
    }

    /**
     * 查询当前登录用户的所有订单
     * @param userId
     * @return
     */
    @Override
    public List<Orders> listOrders(int userId) {
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        OrdersMapper mapper = sqlSession.getMapper(OrdersMapper.class);
        List<Orders> orders = mapper.listOrders(userId);
        return orders;
    }
}
